/**
 * Created by zhangyc on 2017/8/24.
 */

//reducer 根据用户操作，返回新的 state

const initialState = {
  text: 'Hello'
}
const appReducer = (state = initialState, action) => {
  switch (action.type) {
    case 'BUTTON_CLICK':
      //不要直接修改 state，这会使数据改变变得不可监控，
      //这里用的是es7的对象展开运算符(...)，做了一个拷贝操作，也可以用 Object.assign
      return {
        ...state,
        text: action.params
      }
    case 'TITLE_CLICK':
      return {
        ...state,
        text: action.params
      }
    default:
      return initialState;
  }
}

export default appReducer
